//
//  TYZNetworkConfig.m
//  DrivieSchoolStudents
//
//  Created by TangBin on 2019/5/29.
//  Copyright © 2019 班文政. All rights reserved.
//

#import "TYZNetworkConfig.h"
#import "TYZBaseRequest.h"
#import <AFNetworking/AFNetworking.h>

@interface TYZNetworkConfig ()
{
    NSMutableArray<id<TYZUrlFilterProtocol>> *_urlFilters;
    NSMutableArray<id<TYZCacheDirPathFilterProtocol>> *_cacheDirPathFilters;
}
@end

@implementation TYZNetworkConfig

+ (instancetype)sharedConfig
{
    static id instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc] init];
    });
    return instance;
}

- (instancetype)init
{
    if (self = [super init])
    {
        [self setupData];
    }
    return self;
}

- (void)setupData
{
    _baseUrl = @"";
    _urlFilters = [[NSMutableArray alloc] initWithCapacity:0];
    _cacheDirPathFilters = [[NSMutableArray alloc] initWithCapacity:0];
    _securityPolicy = [AFSecurityPolicy defaultPolicy];
    _debugLogEnabled = NO;
}

- (NSArray<id<TYZUrlFilterProtocol>> *)urlFilters
{
    return _urlFilters.copy;
}

- (NSArray<id<TYZCacheDirPathFilterProtocol>> *)cacheDirPathFilters
{
    return _cacheDirPathFilters.copy;
}

#pragma mark - public methods
- (void)addUrlFilter:(id<TYZUrlFilterProtocol>)filter
{
    [_urlFilters addObject:filter];
}

- (void)clearUrlFilter
{
    [_urlFilters removeAllObjects];
}

- (void)addCacheDirPathFilter:(id<TYZCacheDirPathFilterProtocol>)filter
{
    [_cacheDirPathFilters addObject:filter];
}

- (void)clearCacheDirPathFilter
{
    [_cacheDirPathFilters removeAllObjects];
}

- (NSString *)description
{
    return [NSString stringWithFormat:@"<%@: %p>{ baseURL: %@ }", NSStringFromClass([self class]), self, self.baseUrl];
}

@end





























